package com.ruoyi.pipe.cctv.service.impl;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.pipe.cctv.mapper.BizPipeCctvMapper;
import com.ruoyi.pipe.cctv.domain.BizPipeCctv;
import com.ruoyi.pipe.cctv.service.IBizPipeCctvService;
import com.ruoyi.system.api.RemoteFileService;

import breeze.framework.reflect.Reflector;

/**
 * 官道网络cctv检测结果数据表Service业务层处理
 * 
 * @author breeze
 * @date 2022-11-29
 */
@Service
public class BizPipeCctvServiceImpl extends ServiceImpl<BizPipeCctvMapper,BizPipeCctv> implements IBizPipeCctvService {
    
    @Autowired
    private BizPipeCctvMapper bizPipeCctvMapper;
    
    @Autowired
    private RemoteFileService remoteFileService;

    @Override
    public BizPipeCctv selectBizPipeCctvById(Long id){
    	BizPipeCctv bizPipeCctv = bizPipeCctvMapper.selectBizPipeCctvById(id);
    	setSingleFile("videoFileIds","videoFiles",bizPipeCctv);
		setSingleFile("videoProcessedFileIds","videoProcessedFiles",bizPipeCctv);
		setSingleFile("imageFileIds","imageFiles",bizPipeCctv);
		setSingleFile("imageProcessedFileIds","imageProcessedFiles",bizPipeCctv);
        return bizPipeCctv;
    }
      
    @Override
    public List<BizPipeCctv> selectBizPipeCctvList(BizPipeCctv bizPipeCctv){
    	List<BizPipeCctv> bizPipeCctvs = bizPipeCctvMapper.selectBizPipeCctvList(bizPipeCctv);
    	for (int i = 0; i < bizPipeCctvs.size(); i++) {
    		BizPipeCctv _bizPipeCctv = bizPipeCctvs.get(i);
    		setSingleFile("videoFileIds","videoFiles",_bizPipeCctv);
    		setSingleFile("videoProcessedFileIds","videoProcessedFiles",_bizPipeCctv);
    		setSingleFile("imageFileIds","imageFiles",_bizPipeCctv);
    		setSingleFile("imageProcessedFileIds","imageProcessedFiles",_bizPipeCctv);
    	}
    	return bizPipeCctvs;
    }

	@Override
	public List<BizPipeCctv> selectBizPipeCctvFaultList(BizPipeCctv bizPipeCctv) {
    	List<BizPipeCctv> bizPipeCctvs = bizPipeCctvMapper.selectBizPipeCctvFaultList(bizPipeCctv);
    	for (int i = 0; i < bizPipeCctvs.size(); i++) {
    		BizPipeCctv _bizPipeCctv = bizPipeCctvs.get(i);
    		setSingleFile("videoFileIds","videoFiles",_bizPipeCctv);
    		setSingleFile("videoProcessedFileIds","videoProcessedFiles",_bizPipeCctv);
    		setSingleFile("imageFileIds","imageFiles",_bizPipeCctv);
    		setSingleFile("imageProcessedFileIds","imageProcessedFiles",_bizPipeCctv);
    	}
		return bizPipeCctvs;
	}

	@Override
	public List<Map<String, Object>> selectFaultEvaluate(BizPipeCctv bizPipeCctv) {
		return bizPipeCctvMapper.selectFaultEvaluate(bizPipeCctv);
	}
	
	private void setSingleFile(String idProperty,String fileProperty,Object obj) {
		Object propertyValue = Reflector.getProperty(obj, idProperty);
		if(null != propertyValue && !"".equals(propertyValue.toString())) {
			try {
				Long fileId = Long.parseLong(propertyValue.toString());
				Reflector.setProperty(obj, fileProperty, remoteFileService.getInfo(fileId).getData());
			} catch (Exception e) {
			}
		}
		
	}
}
